package com.jt.controller;


import com.jt.service.FileService;
import com.jt.vo.ImageVO;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.multipart.MultipartFile;

import java.io.File;
import java.io.IOException;

@RestController
public class FileController {

    @Autowired
    private FileService fileService;

    @RequestMapping("/file")
    public String file(MultipartFile fileImage) {
        String fileDirPath = "D:/JT-SOFT/images";
        File dirFile = new File(fileDirPath);
        if (!dirFile.exists()) {
            dirFile.mkdir();
        }

        String fileName = fileImage.getOriginalFilename();
        File realFile = new File(fileDirPath + "/" + fileName);

        try {
            fileImage.transferTo(realFile);
            return "文件上传成功";
        } catch (IOException e) {
            e.printStackTrace();
            return "文件上传失败";
        }



    }

    @RequestMapping("/pic/upload")
    public ImageVO upload(MultipartFile uploadFile) {
        return fileService.upload(uploadFile);
    }
}
